package com.cake21.test.webtest.page;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

import com.cake21.test.webtest.Constants;

public class CakeList {
	
	WebDriver driver;
	
	@FindBy(className="gallery-list")
	private WebElement listDiv;
	
	@FindBy(css=".goods-item")
	private List<WebElement> goodsList;
	

	public CakeList(WebDriver driver) {
		this.driver = driver;
		driver.get(Constants.CakeListURL);
		PageFactory.initElements(driver, this);
	}
	
	public int getGoodsCount()
	{
		return goodsList.size();
	}
	
	public Cake goCakeDetail()
	{
		int total = goodsList.size();
		int randomNumber = (int)(Math.random()*total) + 1;
		WebElement cake = goodsList.get(randomNumber);
		System.out.println("Random Number: " + randomNumber);
		cake.findElement(By.cssSelector(".action-view")).click();
		return new Cake(driver);
	}
}
